package cn.epsilon3.mybatis.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cn.epsilon3.constant.Base;
import cn.epsilon3.domain.e3.po.E3UserPo;
import cn.epsilon3.mybatis.mapper.E3UserMapper;
import cn.epsilon3.mybatis.service.E3UserMapperService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 * user mapper 服务
 * </p>
 *
 * @author epsilon3
 * @since 2023-08-13
 */
@Service
public class E3UserMapperServiceImpl implements E3UserMapperService {

    @Resource
    private E3UserMapper e3UserMapper;

    @Override
    @Transactional(readOnly = true)
    public E3UserPo selectOneByUserCount(String userAccount) {
        if (StrUtil.isBlank(userAccount)) {
            return null;
        }
        return e3UserMapper.selectOne(Wrappers.<E3UserPo>lambdaQuery()
                .eq(E3UserPo::getUserName, userAccount)
                .or()
                .eq(E3UserPo::getUserEmail, userAccount)
                .eq(E3UserPo::getEffective, Base.INT0));
    }

    @Override
    @Transactional(readOnly = true)
    public E3UserPo selectOneByUserId(String userId,Integer effective) {
        if (StrUtil.isBlank(userId)) {
            return null;
        }
        return e3UserMapper.selectOne(Wrappers.<E3UserPo>lambdaQuery()
                .eq(E3UserPo::getId, userId)
                .eq(E3UserPo::getEffective,effective));
    }

    @Override
    @Transactional
    public void updateOneByUserId(E3UserPo e3UserPo) {
        e3UserMapper.updateById(e3UserPo);
    }
}
